/**
* A multi-wiki, multi-master factory for Wikimedia and similar installations.
- * Ignores the old configuration globals
+ * Ignores the old configuration globals.
+ *
+ * Template override precedence (highest => lowest):
+ * - templateOverridesByServer
+ * - masterTemplateOverrides
+ * - templateOverridesBySection/templateOverridesByCluster
+ * - externalTemplateOverrides
+ * - serverTemplate
+ * Overrides only work on top level keys (so nested values will not be merged).
*
* Configuration:
* sectionsByDB A map of database names to section names.
*
* sectionLoads A 2-d map. For each section, gives a map of server names to
* load ratios. For example:
- * array(
- * 'section1' => array(
+ * [
+ * 'section1' => [
* 'db1' => 100,
* 'db2' => 100
- * )
- * )
+ * ]
+ * ]
*
* serverTemplate A server info associative array as documented for $wgDBservers.
* The host, hostName and load entries will be overridden.
*
* groupLoadsBySection A 3-d map giving server load ratios for each section and group.
* For example:
- * array(
- * 'section1' => array(
- * 'group1' => array(
+ * [
+ * 'section1' => [
+ * 'group1' => [
* 'db1' => 100,
* 'db2' => 100
- * )
- * )
- * )
+ * ]
+ * ]
+ * ]
*
* groupLoadsByDB A 3-d map giving server load ratios by DB name.
*
* templateOverridesByServer A 2-d map overriding serverTemplate and
* externalTemplateOverrides on a server-by-server basis. Applies
* to both core and external storage.
- *
+ * templateOverridesBySection A 2-d map overriding the server info by section.
* templateOverridesByCluster A 2-d map overriding the server info by external storage cluster.
*
* masterTemplateOverrides An override array for all master servers.
// Optional settings
/** @var array A 3-d map giving server load ratios for each section and group */
- private $groupLoadsBySection = array();
+ private $groupLoadsBySection = [];
/** @var array A 3-d map giving server load ratios by DB name */
- private $groupLoadsByDB = array();
+ private $groupLoadsByDB = [];
/** @var array A map of hostname to IP address */
- private $hostsByName = array();
+ private $hostsByName = [];
/** @var array A map of external storage cluster name to server load map */
- private $externalLoads = array();
+ private $externalLoads = [];
/**
* @var array A set of server info keys overriding serverTemplate for
*/
private $templateOverridesByServer;
+ /** @var array A 2-d map overriding the server info by section */
+ private $templateOverridesBySection;
+
/** @var array A 2-d map overriding the server info by external storage cluster */
private $templateOverridesByCluster;
* @var array|bool A map of section name to read-only message. Missing or
* false for read/write
*/
- private $readOnlyBySection = array();
+ private $readOnlyBySection = [];
// Other stuff
private $conf;
/** @var LoadBalancer[] */
- private $mainLBs = array();
+ private $mainLBs = [];
/** @var LoadBalancer[] */
- private $extLBs = array();
+ private $extLBs = [];
/** @var string */
private $loadMonitorClass;
parent::__construct( $conf );
$this->conf = $conf;
- $required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
- $optional = array( 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
+ $required = [ 'sectionsByDB', 'sectionLoads', 'serverTemplate' ];
+ $optional = [ 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
- 'templateOverridesByCluster', 'masterTemplateOverrides',
- 'readOnlyBySection', 'loadMonitorClass' );
+ 'templateOverridesByCluster', 'templateOverridesBySection', 'masterTemplateOverrides',
+ 'readOnlyBySection', 'loadMonitorClass' ];
foreach ( $required as $key ) {
if ( !isset( $conf[$key] ) ) {
if ( isset( $this->groupLoadsByDB[$dbName] ) ) {
$groupLoads = $this->groupLoadsByDB[$dbName];
} else {
- $groupLoads = array();
+ $groupLoads = [];
}
if ( isset( $this->groupLoadsBySection[$section] ) ) {
$readOnlyReason = $this->readOnlyBySection[$section];
}
+ $template = $this->serverTemplate;
+ if ( isset( $this->templateOverridesBySection[$section] ) ) {
+ $template = $this->templateOverridesBySection[$section] + $template;
+ }
+
return $this->newLoadBalancer(
- $this->serverTemplate,
+ $template,
$this->sectionLoads[$section],
$groupLoads,
$readOnlyReason
$section = $this->getSectionForWiki( $wiki );
if ( !isset( $this->mainLBs[$section] ) ) {
$lb = $this->newMainLB( $wiki );
- $lb->parentInfo( array( 'id' => "main-$section" ) );
+ $lb->parentInfo( [ 'id' => "main-$section" ] );
$this->chronProt->initLB( $lb );
$this->mainLBs[$section] = $lb;
}
return $this->newLoadBalancer(
$template,
$this->externalLoads[$cluster],
- array(),
+ [],
$this->readOnlyReason
);
}
public function &getExternalLB( $cluster, $wiki = false ) {
if ( !isset( $this->extLBs[$cluster] ) ) {
$this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
- $this->extLBs[$cluster]->parentInfo( array( 'id' => "ext-$cluster" ) );
+ $this->extLBs[$cluster]->parentInfo( [ 'id' => "ext-$cluster" ] );
$this->chronProt->initLB( $this->extLBs[$cluster] );
}
* @return LoadBalancer
*/
private function newLoadBalancer( $template, $loads, $groupLoads, $readOnlyReason ) {
- return new LoadBalancer( array(
+ return new LoadBalancer( [
'servers' => $this->makeServerArray( $template, $loads, $groupLoads ),
'loadMonitor' => $this->loadMonitorClass,
'readOnlyReason' => $readOnlyReason,
'trxProfiler' => $this->trxProfiler
- ) );
+ ] );
}
/**
* @return array
*/
private function makeServerArray( $template, $loads, $groupLoads ) {
- $servers = array();
+ $servers = [];
$master = true;
$groupLoadsByServer = $this->reindexGroupLoads( $groupLoads );
foreach ( $groupLoadsByServer as $server => $stuff ) {
* @return array
*/
private function reindexGroupLoads( $groupLoads ) {
- $reindexed = array();
+ $reindexed = [];
foreach ( $groupLoads as $group => $loads ) {
foreach ( $loads as $server => $load ) {
$reindexed[$server][$group] = $load;
if ( $wiki === false ) {
global $wgDBname, $wgDBprefix;
- return array( $wgDBname, $wgDBprefix );
+ return [ $wgDBname, $wgDBprefix ];
} else {
return wfSplitWikiID( $wiki );
}
* @param callable $callback
* @param array $params
*/
- public function forEachLB( $callback, array $params = array() ) {
+ public function forEachLB( $callback, array $params = [] ) {
foreach ( $this->mainLBs as $lb ) {
- call_user_func_array( $callback, array_merge( array( $lb ), $params ) );
+ call_user_func_array( $callback, array_merge( [ $lb ], $params ) );
}
foreach ( $this->extLBs as $lb ) {
- call_user_func_array( $callback, array_merge( array( $lb ), $params ) );
+ call_user_func_array( $callback, array_merge( [ $lb ], $params ) );
}
}